<!DOCTYPE html>
<html lang="zh-cmn-Hans">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0,viewport-fit=cover">
    <title>扫码实名认证</title>
    <link rel="stylesheet" href="/static/weui/css/weui.min.css" />
</head>

<body ontouchstart>
    <div class="container" id="container" style="text-align: center;">

        <div class="page">
            <div id="codeDiv" style="display: none;"></div>
            <div id="qrcode" style="margin: 20px auto !important"></div>
        </div>
        <div>扫码实名认证</div>

    </div>

    <script src="/static/weui/js/zepto.min.js"></script>
    <script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
    <script src="https://res.wx.qq.com/open/libs/weuijs/1.2.1/weui.min.js"></script>
    <script src="/static/weui/js/qrcode.min.js"></script>
    <script type="text/javascript">
    function makeQrcode(url) {
        var qrcode = new QRCode(document.getElementById("codeDiv"), {
            text: url,
            render: "canvas",
            width: 200,
            height: 200,
            typeNumber:-1,//计算模式
            colorDark : "#000000",
            colorLight : "#ffffff",
            correctLevel : QRCode.CorrectLevel.H
        });
        var canvas=document.getElementsByTagName('canvas')[0];
        var img = convertCanvasToImage(canvas);
        $('#qrcode').append(img);// 添加DOM
        // 从 canvas 提取图片 image
        function convertCanvasToImage(canvas) {
        // 新建Image对象
        var image = new Image();
        // canvas.toDataURL 返回的是一串Base64编码的URL
        image.src = canvas.toDataURL("image/png");
            return image;
        }
    }
    $.ajax({
        url: 'https://ai.kipoo.cn/api/faceprint/getAuthUrl',
        type: 'post',
        dataType: 'json',
        data: {
            operator_id: 1024
        },
        success: function(res) {
            if (res.code == 200) {
                console.log(res)
                makeQrcode(res.data.url)
            } else {
                alert(res.message)
            }
        }
    })
</script>
</body>

</html>
